package com.authManager.server.service.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.authManager.entity.SysRole;
import com.authManager.server.dao.SysRoleMapper;
import com.authManager.server.service.ISysRoleService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.commons.base.model.AdminPage;
import com.commons.base.model.ResultCode;
import com.commons.base.model.ResultData;

/**
 * <p>
 * 【角色信息】 服务实现类
 * </p>
 *
 * @author 小旋风
 * @since 2018-8-13
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

	@SuppressWarnings("unused")
	private static final Logger log = LoggerFactory.getLogger(SysRoleServiceImpl.class);

	@Override
	public ResultData<AdminPage<SysRole>> listSysRole(Map<String, Object> paramMap) {
		Page<SysRole> page = new Page<>(Integer.valueOf(String.valueOf(paramMap.get("pageNum"))),
				Integer.valueOf(String.valueOf(paramMap.get("pageSize"))));
		Wrapper<SysRole> entityWrapper = new EntityWrapper<>();

		// 主键id
		if (paramMap.get("sysRoleId") != null) {
			entityWrapper.eq("sys_role.sys_role_id", paramMap.get("sysRoleId"));
		}
		// 角色名
		if (paramMap.get("name") != null) {
			entityWrapper.like("sys_role.name", String.valueOf(paramMap.get("name")));
		}
		// 排序号
		if (paramMap.get("seq") != null) {
			entityWrapper.eq("sys_role.seq", paramMap.get("seq"));
		}
		// 简介
		if (paramMap.get("description") != null) {
			entityWrapper.like("sys_role.description", String.valueOf(paramMap.get("description")));
		}
		// 角色编码
		if (paramMap.get("roleCode") != null) {
			entityWrapper.like("sys_role.role_code", String.valueOf(paramMap.get("roleCode")));
		}
		// 开始-创建日期
		if (paramMap.get("start_createTime") != null) {
			entityWrapper.le("sys_role.create_time", paramMap.get("start_createTime"));
		}
		// 结束-创建日期
		if (paramMap.get("end_createTime") != null) {
			entityWrapper.le("sys_role.create_time", paramMap.get("end_createTime"));
		}
		this.selectPage(page, entityWrapper);
		return new ResultData.Builder<AdminPage<SysRole>>(ResultCode.success).setData(new AdminPage<SysRole>(page))
				.build();
	}
}
